﻿using System;
using System.Collections.Generic;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class DAOQuanLyDiem
    {
        public static DataTable LietKeLookupEditData(string nameproc)
        {
            try
            {
                DataTable kq = SQLDataProvider.ExecuteQuery(nameproc);
                return kq;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable LietKeLop(object makhoilop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                if(makhoilop != null)
                    sqlParams.Add(new SqlParameter("@MAKHOILOP", makhoilop.ToString()));
                else
                    sqlParams.Add(new SqlParameter("@MAKHOILOP", ""));
                return SQLDataProvider.ExecuteQuery("sp_TraCuuDanhSachLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static DataTable LietKeMonHoc(object makhoilop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                if (makhoilop != null)
                    sqlParams.Add(new SqlParameter("@MAKHOILOP", makhoilop.ToString()));
                else
                    sqlParams.Add(new SqlParameter("@MAKHOILOP", ""));
                return SQLDataProvider.ExecuteQuery("sp_LietKeMonHocKhoiLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static DataTable BangDiemHocSinh(object malop, DTODiem diem)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MALOP", malop.ToString()));
                sqlParams.Add(new SqlParameter("@MAHK",diem.MaHK));
                sqlParams.Add(new SqlParameter("@MAMH", diem.MaMH));
                return SQLDataProvider.ExecuteQuery("sp_BangDiemHocSinh", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }

        public static int CapNhatDiemHocSinh(DTODiem diem)
        {
            try
            {
                string sqlstring = "UPDATE DIEM";
                sqlstring = sqlstring + string.Format(" SET DIEM15P = '{0}', DIEM1T = '{1}', DIEMTHI = '{2}', DIEMTB = '{3}' WHERE MAHS = '{4}' AND MAMONHOC = '{5}' AND MAHK = '{6}'", diem.Diem15P, diem.Diem1T, diem.DiemThi, diem.DiemTB, diem.MaHS, diem.MaMH, diem.MaHK);
                SQLDataProvider.ExecuteQueryString(sqlstring);
                return 1;
                //List<SqlParameter> sqlParams = new List<SqlParameter>();
                //sqlParams.Add(new SqlParameter("@MAHS", diem.MaHS));
                //sqlParams.Add(new SqlParameter("@MAMH", diem.MaMH));
                //sqlParams.Add(new SqlParameter("@MAHK", diem.MaHK));
                //sqlParams.Add(new SqlParameter("@DIEM15P", diem.Diem15P));
                //sqlParams.Add(new SqlParameter("@DIEM1T", diem.Diem1T));
                //sqlParams.Add(new SqlParameter("@DIEMTHI", diem.DiemThi));
                //sqlParams.Add(new SqlParameter("@DIEMTB", diem.DiemTB));
                //return SQLDataProvider.ExecuteNoneQuery("sp_CapNhatDiemHocSinh", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }  
        }
    }
}
